﻿if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].CdcIsUpdated') and OBJECTPROPERTY(id, N'IsScalarFunction') = 1)
DROP FUNCTION [dbo].CdcIsUpdated

GO

CREATE FUNCTION dbo.CdcIsUpdated
(
	@updatedBitMask varbinary(128),
	@requiredBitMask varbinary(128)
)
RETURNS bit	
AS
BEGIN
	DECLARE @ByteIdx tinyint
	SET @ByteIdx=DATALENGTH(@updatedBitMask)
	
	WHILE @ByteIdx > 0
	BEGIN
		IF substring(@updatedBitMask, @ByteIdx, 1)  & cast(substring(@requiredBitMask, @ByteIdx, 1) as tinyint) <> 0 RETURN 1
		SET @ByteIdx = @ByteIdx-1
	END

	RETURN 0
END

GO

exec sp_addextendedproperty 'CdcDbType', 'CdcTracked', NULL, NULL, NULL, NULL